< previous page page_9 next page >

Page 9
These functions are provided by a drawing object. This code does not specify an object, so Visual Basic uses the current form. This is equivalent to the following statement.
e10a6a0a59f035e870d90cca05b85fce.gif
dist_pixels = Me.ScaleX(120, vbTwips, vbPixels)
Usually, it does not matter what object a program uses to convert from one coordinate system to another. Converting from inches to twips gives the same result no matter what object performs the conversion. There are 1440 twips per logical inch whether the drawing object is a form, picture box, or printer.
However, when an object has a custom coordinate system, using the correct properties is very important. If either of the ScaleMode values is vbUser, the object uses its own custom coordinates in the conversion. For example, suppose you want to draw a box five pixels square on a form that uses a custom coordinate system. You can use the form's ScaleX and ScaleY functions to convert the value five pixels into the form's coordinate system. Note that the form may scale differently in the X and Y directions, so its ScaleX and ScaleY functions may return different results.
Example program Bars3 uses the following code to draw a red box five pixels square. Once again, ignore the details of drawing the box for now. Focus instead on the use of the ScaleX and ScaleY functions.
e10a6a0a59f035e870d90cca05b85fce.gif
Dim wid As Single 
Dim hgt As Single
        :
    ' Draw a 5 by 5 pixel box at position 
    ' (NUM_VALUES / 2 + 1, 50). 
    wid = ScaleX(5, vbPixels, ScaleMode) 
    hgt = ScaleY(5, vbPixels, ScaleMode) 
    Line (NUM_VALUES / 2 + 1, 50)-Step(wid, hgt), vbRed, BF
Size and Positioning
The ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties determine the coordinates Visual Basic uses within a drawing object. The Top, Left, Width, and Height properties determine the object's size and position within its parent.
For a form or printer object, these properties are always measured in twips. For a picture box or other control, they are measured in the units used by the form or control that contains the object. For example, if a picture box is contained within another picture box with ScaleMode set to vbPixels, you must specify the position and size of the inner picture box using pixels. Figure 1.3 shows how these properties determine an object's position.
For forms, the Width and Height properties include the space taken up by borders and the form's title bar. Figure 1.4 shows the relationship between the Width, ScaleWidth, Height, and ScaleHeight properties for a form.

 
< previous page page_9 next page >